package com.dao;

import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author :wn
 * @program : 项目五登录界面
 * @descript :
 * @create :2020-10-28 22:52
 */

public class UserDao implements DaoImpl {

    public boolean queryMethod(String name,String password) throws SQLException, NamingException {
           boolean query=false;
            Connection connection=getConnection("java:comp/env/jdbc/userDatasource");
            Statement st = connection.createStatement();
            String sql="select * from familyuser where username='"+name+"' and userpassword='"+password+"'";
            ResultSet rs=st.executeQuery(sql);
         if(rs.next()){
             query=true;
         }else {
             query = false;
         }
         connection.close();
        return  query;
    }
    public boolean addUser(String name,String password,String confirmPassword) throws SQLException, NamingException {
        boolean adder = false;
        Connection con=getConnection("java:comp/env/jdbc/userDatasource");
        Statement st=con.createStatement();
        if(password.equals(confirmPassword)) {
            String sql = "insert into familyuser(username,userpassword) values('"+name+"','"+ password+"') ";
           st.execute(sql);
           adder=true;
        }
        con.close();
        return adder;
    }


    @Override
    public boolean queryMethod() {
        return false;
    }

    @Override
    public void updateWay() {

    }

    @Override
    public void addWay() {

    }

    @Override
    public void deletWay() {

    }
}
